<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title"></h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!home">首页</a>
          <a><cite></cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
                      搜索：  <select id="clubevaluation-search-key">
            <option value="">-请选择-</option>
                 <option value="id">ID</option>
                 <option value="club_id">博文ID</option>
                 <option value="title">评价标题</option>
                 <option value="content">评价内容</option>
                 <option value="member_id">评价人</option>
                 <option value="create_date">评价时间</option>
                 </select>&emsp;
            <input id="clubevaluation-search-value" class="layui-input search-input" type="text" placeholder="输入关键字"/>&emsp;
            <button id="clubevaluation-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
        </div>

        <table class="layui-table" id="clubevaluation-table" lay-filter="clubevaluation-table"></table>
    </div>
</div>


<!-- 表格操作列 -->
<script type="text/html" id="clubevaluation-table-bar">
 {{#   if(admin.hasPerm("cms:clubevaluation:update") ){   }}
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
 {{#     } }} 
 {{#  if(admin.hasPerm("cms:clubevaluation:delete") ){   }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
 {{#     } }} 
</script>


<script type="text/html" id="toolbar">
     {{#  if(admin.hasPerm("cms:clubevaluation:save")){ }}
     <button id="clubevaluation-btn-add" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
     {{#     } }} 
 
</script>

<script>
   var admin;
    layui.use(['form', 'table', 'util', 'config', 'admin', 'upload','laytpl','element' ], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var layer = layui.layer;
        var util = layui.util;
          admin = layui.admin;
        //上传
        var upload = layui.upload;
        let laytpl = layui.laytpl;
        let element = layui.element;

        // 渲染表格
        table.render({
            elem: '#clubevaluation-table',
            url: config.base_server + 'cms/clubevaluation/list',
            method: 'GET',
       
            page: true,
            cols: [[
                {type: 'numbers'},
                           {field: 'id', sort: true, title: 'ID'},
                           {field: 'clubId', sort: true, title: '博文ID'},
                           {field: 'title', sort: true, title: '评价标题'},
                           {field: 'content', sort: true, title: '评价内容'},
                           {field: 'memberId', sort: true, title: '评价人'},
                           {field: 'createDate', sort: true, title: '评价时间'},
                        
                {fixed: 'right', align: 'center', toolbar: '#clubevaluation-table-bar', title: '操作', width: 175}
            ]]
        });
        
        laytpl($("#toolbar")[0].innerHTML).render({ }, function(html){
			  $(".layui-card-body .toolbar").append(html);
			  element.render('nav');
		  });

        // 添加按钮点击事件
        $('#clubevaluation-btn-add').click(function () {
            showEditModel();
        });

        // 工具条点击事件
        table.on('tool(clubevaluation-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            if (layEvent === 'edit') { // 修改
             
                showEditModel(data);
            }  else if (layEvent === 'del') { // 删除
                layer.confirm('确定删除吗？', function (i) {
                    layer.close(i);
                    layer.load(2);
                    admin.req('cms/clubevaluation/delete/'+obj.data.id, {}, function (data) {
                        layer.closeAll('loading');
                        if (data.code == 0) {
                            layer.msg(data.msg, {icon: 1, time: 500});
                            table.reload('clubevaluation-table', {});
                        } else {
                            layer.msg(data.msg, {icon: 2, time: 500});
                        }
                    }, 'delete');
                });
            }
        });

        //显示表单弹窗
        var showEditModel = function (data) {
        	  var title = data ? '修改用户' : '添加用户';
            //修改方法名
            if (data){
                data.method="update"
            }else{
            	data={method:"save"};
            }
 
            admin.putTempData('t_clubevaluation', data);
            admin.popupCenter({
                title: title,
                path: 'pages/cms/clubevaluation_form.html',
                finish: function () {
                    table.reload('clubevaluation-table', {});
                }
            });
        };

        // 搜索按钮点击事件
        $('#clubevaluation-btn-search').click(function () {
            var key = $('#clubevaluation-search-key').val();
            var value = $('#clubevaluation-search-value').val();
            table.reload('clubevaluation-table', {where: {searchKey: key, searchValue: value}});
        });

    });
</script>
